"use strict";
/* Controllers */
app.controller("dpExecuteLogListController", ['$scope', '$location', '$rootScope', '$routeParams', 'dpExecuteLogListService', function ($scope, $location, $rootScope, $routeParams, dpExecuteLogListService) {

    var vm = $scope.vm;

    vm.p = {};
    vm.result = {};
    vm.p.tableName = $routeParams.tableName;
    if(vm.p.tableName == "0"){
        vm.p.tableName = '';
    }

     if (!vm.p.dt) {
        var dt = getNowFormatDate(-1);
        vm.p.dt = dt.substr(0, 4) + "-" + dt.substr(4,2) + "-" + dt.substr(6);
    }

    var errorFn = function (result) {
        alert(result);
    };

    $scope.listDpExecuteLog = function () {
        var vm = $scope.vm;
        var params = $scope.vm.p;
        $('#list_table').bootstrapTable('showLoading');
        $("#refreshTable").addClass('disabled');
        var procFn = function (response) {
            var data = response.data;
            if (data == null) {
                return;
            }
            vm.result.data = data;
            $('#list_table').bootstrapTable('load', data);
            $('#list_table').bootstrapTable('hideLoading');
            $("#refreshTable").removeClass('disabled');
        };
        dpExecuteLogListService.listDpExecuteLog(params, procFn, errorFn);
    };

    $("#refreshTable").click(function () {
        $('#list_table').bootstrapTable('refresh');
        $scope.listDpExecuteLog()
    });

    $scope.initializeController = function () {
        var $resultTable = $('#list_table');
        $resultTable.bootstrapTable({
             pageList: [100, 300, 500], pageSize: 100
        });
        $scope.listDpExecuteLog()
    };

    $scope.initializeController();

}]);


/* Services */
app.service('dpExecuteLogListService', ['ajaxService', function (ajaxService) {

    this.listDpExecuteLog = function (params, successFunction, errorFunction) {
        ajaxService.AjaxPost(params, "/star/api/basic-service/v1/dp_execute_log/findByTableNameAndDt.do", successFunction, errorFunction);
    };


}]);

function runTimeFormatter(val){
    var min = val / 60;
    return min.toFixed(2);
}

function executeLogOpt(value, row, index){
    return '<a type="button" class="btn btn-xs btn-primary" href="#/star/task/dp_execute_log_detail/'+row.uniqueId+'" target="_blank">详情</a>';
}

